#include "MyGDIPlus.h"
#include <string>
using namespace std;

MyGDIPlus::MyGDIPlus()
{
	// Khoi tao thu vien GDI+ 
	GdiplusStartupInput gpSI;

	GdiplusStartup(&gpToken, &gpSI, NULL);

	HWND console = GetConsoleWindow();	// Lay handle cua so cua so console
	/*Graphics g(console);*/
	g = new Graphics(console);	// dan to giay graphic vao cua so console
}

MyGDIPlus::~MyGDIPlus()
{
	delete(g);
	GdiplusShutdown(gpToken);
}

// Ham ve duong thang
void MyGDIPlus::DrawLine(char RGBStroke[], int strokeWidth, int x1, int y1, int x2, int y2)
{
	Pen* pen = new Pen(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]), strokeWidth);
	g->DrawLine(pen, x1, y1, x2, y2);
}


// Ham ve Elipse
void MyGDIPlus::DrawEllipse(char RGBStroke[], int strokeWidth, int x, int y, int width, int height)
{
	Pen* pen = new Pen(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]), strokeWidth);
	g->DrawEllipse(pen , x, y, width, height);
}

// Ham ve hinh chu nhat
void MyGDIPlus::DrawRectangle(char RGBStroke[], int strokeWidth, int x, int y, int width, int height)
{
	Pen* pen = new Pen(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]), strokeWidth);
	g->DrawRectangle(pen, x, y, width, height);
}

// Ham ve Text
void MyGDIPlus::DrawText2(char RGBStroke[], char* text, int size, int x, int y)
{
	////WCHAR string[] = L"Hello"; //= text;
	////string str = text;
	//WCHAR NameBuffer[512];
	//char *str1 ="Hello";
	//swprintf(NameBuffer,L"%s",str1);

	//Brush *brush = new SolidBrush(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]));
	//Font font(L"Arial", size);
	//StringFormat format;
	//format.SetAlignment(StringAlignmentCenter);
	//PointF pos(x, y);
	//
	//g->DrawString(NameBuffer, 11, &font, pos, &format, brush);

}

// Ham ve mui ten
void MyGDIPlus::DrawArrow(char RGBStroke[], int strokeWidth, int x1, int y1, int x2, int y2)
{
	Pen* pen = new Pen(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]), strokeWidth);
	pen->SetEndCap(LineCap::LineCapArrowAnchor);
	g->DrawLine(pen, x1, y1, x2, y2);
}

// Ham to Elipse
void MyGDIPlus::FillEllipse(char RGBStroke[], int x, int y, int width, int height)
{
	Brush* brush = new SolidBrush(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]));
	g->FillEllipse(brush, x, y, width, height);
}

// Ham to hinh chu nhat
void MyGDIPlus::FillRectangle(char RGBStroke[], int x, int y, int width, int height)
{
	Brush* brush = new SolidBrush(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]));
	g->FillRectangle(brush, x, y, width, height);
}

// Ham to hinh chu nhat
void MyGDIPlus::FillPolygon(char RGBStroke[], MyPoint points[], int numPoints)
{
	Brush* brush = new SolidBrush(Color(RGBStroke[0], RGBStroke[1], RGBStroke[2]));
	Point* arrPoint = new Point[numPoints];

	for (int i = 0; i < numPoints; i++)
	{
		arrPoint[i].X = points[i].x;
		arrPoint[i].Y = points[i].y;
	}

	g->FillPolygon(brush, arrPoint, numPoints);

	// Huy mang arrPoint
	//.....
}

// Lay ten thu vien do hoa
string MyGDIPlus::GetName()
{
	return "GDI+";
}